package com.duff.pdf.reader.library;

import android.text.TextUtils;

import java.io.File;

/**
 * Author: duff
 * Date: 2018/3/1
 * Version: 1.0.0
 * Description:
 */

public class Utils {

    /**
     * 获取本地文件或URL的文件名. 包含后缀
     *
     * @param path 本地文件或URL路径
     * @return 文件名
     */
    public static String getFileName(String path) {
        if (TextUtils.isEmpty(path)) {
            return "";
        }

        int query = path.lastIndexOf('?');
        if (query > 0) {
            path = path.substring(0, query);
        }

        int filenamePos = path.lastIndexOf(File.separatorChar);
        return (filenamePos >= 0) ? path.substring(filenamePos + 1) : path;
    }

}
